package com.leyou.item.service.impl;

import com.leyou.common.enums.LyExceptionEnums;
import com.leyou.common.exception.LyException;
import com.leyou.item.entity.Sku;
import com.leyou.item.entity.Stock;
import com.leyou.item.mapper.LyBaseMapper;
import com.leyou.item.mapper.lymapper.SkuMapper;
import com.leyou.item.service.SkuService;
import com.leyou.item.service.StockService;
import com.leyou.item.service.base.AbstractBaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import tk.mybatis.mapper.entity.Example;

import java.util.List;

/**
 * @author linzx
 * @date 2020/3/25
 */
@Service
public class SkuServiceImpl extends AbstractBaseService<Sku> implements SkuService {
    @Autowired
    private SkuMapper skuMapper;
    @Autowired
    private StockService stockService;


    @Override
    protected LyBaseMapper<Sku> getMapper() {
        return skuMapper;
    }


    @Override
    public List<Sku> findSkuWithStockBySpuId(Long spuId) {
        Sku sku = new Sku();
        sku.setSpuId(spuId);
        List<Sku> skuList = this.select(sku);
        skuList.forEach(s -> {
            s.setStock(stockService.selectByPrimaryKey(s.getId()).getStock());
        });
        return skuList;
    }


}
